﻿@model SiteImportWordpressModel

@{
	ViewBag.Title = "Wordpress Import";
}

@if (!String.IsNullOrEmpty(Model.Message)) {
	<fieldset style="width: 90%;">
		<legend>
			<label>
				Import Summary
			</label>
		</legend>
		<div id="divSiteLoadSummary">
			<ul>
				@Html.Raw(Model.Message)
			</ul>
		</div>
	</fieldset>
}

<script type="text/javascript">
	function cmsLoadImportAlert() {
		if ($('#divSiteLoadSummary ul li').length > 0) {
			var txt = $('#divSiteLoadSummary').html();
			cmsAlertModal(txt);
		}
	}

	$(document).ready(function () {
		cmsLoadImportAlert();
	});
</script>

<script type="text/javascript">
	function chkFileGrabClick() {

		var fldr = '#@Html.IdFor(m => m.SelectedFolder)';
		var chk = '#@Html.IdFor(m => m.DownloadImages)';

		var ddlFolders = $(fldr).get(0).selectedIndex;
		var chkFileGrab = $(chk).prop('checked');
		//alert(chkFileGrab + '  -  ' + ddlFolders);

		$(fldr).removeClass('validationErrorBox');

		if (chkFileGrab && ddlFolders < 1) {
			$(fldr).addClass('validationErrorBox');
		}
	}
</script>

@using (Html.BeginForm()) {
	@Html.AntiForgeryToken()

	@Html.HiddenFor(m => m.ImportID)
	@Html.HiddenFor(m => m.HasLoaded)

	<div style="display: none">
		<div id="formPrettyValidationSummary">
			@Html.ValidationSummary(true, "")
		</div>
	</div>

	<p>
		The below information (if checked) will be imported to the current site. You can always update the information after importing.
	</p>
	<fieldset style="width: 90%;">
		<legend>
			<label>
				Import Settings
			</label>
		</legend>
		<table style="width: 75%;">
			<tr>
				<td>
					@Html.CheckBoxFor(m => m.DownloadImages, new { @onclick = "chkFileGrabClick();" })
					@*<input id="chkFileGrab" type="checkbox" name="chkFileGrab" onclick="chkFileGrabClick(this);" />*@
					Attempt to download page/post attachments and place them in the selected folder.
				</td>
				<td>
					&nbsp;&nbsp;&nbsp;
				</td>
				<td>
					<table>
						<tr>
							<td>@Html.DropDownListFor(m => m.SelectedFolder, new SelectList(Model.DownloadFolders, "FileName", "FolderPath"), "[Select Folder]")</td>
							<td>@Html.ValidationMessageFor(m => m.SelectedFolder, "", new { @class = "validationError" })</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					@Html.CheckBoxFor(m => m.FixHtmlBodies)
					@*<input id="chkFixBodies" type="checkbox" name="chkFixBodies" checked="checked" />*@
					Uncheck this box if you want the content bodies to remain in their original format, otherwise paragraph and line break tags will be added.
				</td>
				<td>
					&nbsp;
				</td>
				<td>
					&nbsp;
				</td>
			</tr>
			<tr>
				<td>
					@Html.CheckBoxFor(m => m.CreateUsers)
					@*<input id="chkAuthors" type="checkbox" name="chkAuthors" checked="checked" />*@
					Uncheck this box if you do not want new user accounts to be created. Accounts will only be created if the username and email address have not
					already been used in this system. Password will be set according to normal reset values, and the user will have to request a new password by
					email to login. If this is unchecked and a matching account exists, the discovered user will be recorded as the content editor. If the user
					account does not exist, the current user will be recorded as the content editor.
				</td>
				<td>
					&nbsp;
				</td>
				<td>
					&nbsp;
				</td>
			</tr>
			<tr>
				<td>
					@Html.CheckBoxFor(m => m.MapUsers)
					@*<input id="chkMapAuthor" type="checkbox" name="chkMapAuthor" checked="checked" />*@
					Uncheck this box if you want all imported content to be recorded under the current user. This option trumps the account creation checkbox.
				</td>
				<td>
					&nbsp;
				</td>
				<td>
					&nbsp;
				</td>
			</tr>
		</table>
	</fieldset>

	<fieldset style="width: 90%;">
		<legend>
			<label>
				Site Information
				@Html.CheckBoxFor(m => m.ImportSite)
				@Html.Partial("_displayErrorPopupButton")
			</label>
		</legend>
		<table style="width: 99%;">
			<tr>
				<td class="tablecaption" style="width: 200px;">
					Exported from WP Version
				</td>
				<td>
					@Model.Site.wxrVersion
					@Html.HiddenFor(m => m.Site.wxrVersion)
				</td>
			</tr>
			<tr>
				<td class="tablecaption">
					Export Date
				</td>
				<td>
					@Model.Site.ExtractDate
					@Html.HiddenFor(m => m.Site.ExtractDate)
				</td>
			</tr>
			<tr>
				<td colspan="2">
					&nbsp;
				</td>
			</tr>
			<tr>
				<td class="tablecaption">
					Site Name
				</td>
				<td>
					@Model.Site.SiteTitle
					@Html.HiddenFor(m => m.Site.SiteTitle)
				</td>
			</tr>
			<tr>
				<td class="tablecaption">
					Site Description
				</td>
				<td>
					@Model.Site.SiteDescription
					@Html.HiddenFor(m => m.Site.SiteDescription)
				</td>
			</tr>
		</table>
	</fieldset>

	<fieldset style="width: 90%;">
		<legend>
			<label>
				Pages
				@Html.CheckBoxFor(m => m.ImportPages)
				@Html.Partial("_displayErrorPopupButton")
			</label>
		</legend>
		<table>
			<tr>
				<td class="tablecaption">
					template:
				</td>
				<td>
					@Html.DropDownListFor(m => m.PageTemplate, new SelectList(Model.Templates, "TemplatePath", "Caption"))
				</td>
			</tr>
		</table>
		<p>
			@String.Format(" {0} records", Model.Site.ContentPages.Count)
		</p>

		@{
	var pageGrid = CarrotWeb.CarrotWebGrid<WordPressPost>(Model.Site.ContentPages.OrderBy(s => s.PostOrder).ToList());

	pageGrid.TableAttributes = new { @class = "datatable" };
	pageGrid.THeadAttributes = new { @class = "tablehead" };
	pageGrid.EmptyDataTemplate = @<text><p> <b>No records found.</b> </p></text>;
	pageGrid.UseDataPage = false;
	pageGrid.ConfigName(Html.NameFor(x => Model.Site.ContentPages));

	pageGrid
		.AddColumn(x => x.PostOrder, new CarrotGridColumn())
		.AddColumn(x => x.ImportFileName, new CarrotGridColumn())
		.AddColumn(x => x.PostTitle, new CarrotGridColumn())
		.AddColumn(x => x.PostDateUTC, new CarrotGridColumn { CellFormatString = "{0:M/d/yyyy}" })
		.AddColumn(x => x.IsPublished, new CarrotGridBooleanImageColumn());

		@pageGrid.OutputHtmlBody()
		}
	</fieldset>
	<fieldset style="width: 90%;">
		<legend>
			<label>
				Blog Posts
				@Html.CheckBoxFor(m => m.ImportPosts)
				@Html.Partial("_displayErrorPopupButton")
			</label>
		</legend>
		<table>
			<tr>
				<td class="tablecaption">
					template:
				</td>
				<td>
					@Html.DropDownListFor(m => m.PostTemplate, new SelectList(Model.Templates, "TemplatePath", "Caption"))
				</td>
			</tr>
		</table>
		<p>
			@String.Format(" {0} records", Model.Site.ContentPosts.Count)
		</p>

		@{
	var postGrid = CarrotWeb.CarrotWebGrid<WordPressPost>(Model.Site.ContentPosts.OrderByDescending(s => s.PostDateUTC).ToList());

	postGrid.TableAttributes = new { @class = "datatable" };
	postGrid.THeadAttributes = new { @class = "tablehead" };
	postGrid.EmptyDataTemplate = @<text><p> <b>No records found.</b> </p></text>;
	postGrid.UseDataPage = false;
	postGrid.ConfigName(Html.NameFor(x => Model.Site.ContentPosts));

	postGrid
		.AddColumn(x => x.ImportFileName, new CarrotGridColumn())
		.AddColumn(x => x.PostTitle, new CarrotGridColumn())
		.AddColumn(x => x.PostDateUTC, new CarrotGridColumn { CellFormatString = "{0:M/d/yyyy}" })
		.AddColumn(x => x.IsPublished, new CarrotGridBooleanImageColumn());

		@postGrid.OutputHtmlBody()
		}
	</fieldset>

	<p>
		<input type="submit" name="btnSave" value="Apply Changes" id="btnSave" />
	</p>
}